<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 */
class Application_Model_Semestre extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_Idsemestre;

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_FormationIdformation;

    /**
     * Database var type varchar(45)
     *
     * @var string
     */
    protected $_IdAnneeUniv;

    /**
     * Database var type varchar(45)
     *
     * @var string
     */
    protected $_SemestreListIdsemestre;


    /**
     * Parent relation fk_semestre_Annee_univ1
     *
     * @var Application_Model_AnneeUniv
     */
    protected $_AnneeUniv;

    /**
     * Parent relation fk_semestre_formation
     *
     * @var Application_Model_Formation
     */
    protected $_Formation;

    /**
     * Parent relation fk_semestre_semestre_list1
     *
     * @var Application_Model_SemestreList
     */
    protected $_SemestreList;


    /**
     * Dependent relation fk_courselot_semestre1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_Course
     */
    protected $_Course;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'idsemestre'=>'Idsemestre',
            'formation_idformation'=>'FormationIdformation',
            'idAnnee_univ'=>'IdAnneeUniv',
            'semestre_list_idsemestre'=>'SemestreListIdsemestre',
        ));

        $this->setParentList(array(
            'FkSemestreAnneeUniv1'=> array(
                    'property' => 'AnneeUniv',
                    'table_name' => 'AnneeUniv',
                ),
            'FkSemestreFormation'=> array(
                    'property' => 'Formation',
                    'table_name' => 'Formation',
                ),
            'FkSemestreSemestreList1'=> array(
                    'property' => 'SemestreList',
                    'table_name' => 'SemestreList',
                ),
        ));

        $this->setDependentList(array(
            'FkCourselotSemestre1' => array(
                    'property' => 'Course',
                    'table_name' => 'Course',
                ),
        ));
    }

    /**
     * Sets column idsemestre
     *
     * @param int $data
     * @return Application_Model_Semestre
     */
    public function setIdsemestre($data)
    {
        $this->_Idsemestre = $data;
        return $this;
    }

    /**
     * Gets column idsemestre
     *
     * @return int
     */
    public function getIdsemestre()
    {
        return $this->_Idsemestre;
    }

    /**
     * Sets column formation_idformation
     *
     * @param int $data
     * @return Application_Model_Semestre
     */
    public function setFormationIdformation($data)
    {
        $this->_FormationIdformation = $data;
        return $this;
    }

    /**
     * Gets column formation_idformation
     *
     * @return int
     */
    public function getFormationIdformation()
    {
        return $this->_FormationIdformation;
    }

    /**
     * Sets column idAnnee_univ
     *
     * @param string $data
     * @return Application_Model_Semestre
     */
    public function setIdAnneeUniv($data)
    {
        $this->_IdAnneeUniv = $data;
        return $this;
    }

    /**
     * Gets column idAnnee_univ
     *
     * @return string
     */
    public function getIdAnneeUniv()
    {
        return $this->_IdAnneeUniv;
    }

    /**
     * Sets column semestre_list_idsemestre
     *
     * @param string $data
     * @return Application_Model_Semestre
     */
    public function setSemestreListIdsemestre($data)
    {
        $this->_SemestreListIdsemestre = $data;
        return $this;
    }

    /**
     * Gets column semestre_list_idsemestre
     *
     * @return string
     */
    public function getSemestreListIdsemestre()
    {
        return $this->_SemestreListIdsemestre;
    }

    /**
     * Sets parent relation IdAnneeUniv
     *
     * @param Application_Model_AnneeUniv $data
     * @return Application_Model_Semestre
     */
    public function setAnneeUniv(Application_Model_AnneeUniv $data)
    {
        $this->_AnneeUniv = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idAnnee_univ'];
        }

        $this->setIdAnneeUniv($primary_key);

        return $this;
    }

    /**
     * Gets parent IdAnneeUniv
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_AnneeUniv
     */
    public function getAnneeUniv($load = true)
    {
        if ($this->_AnneeUniv === null && $load) {
            $this->getMapper()->loadRelated('FkSemestreAnneeUniv1', $this);
        }

        return $this->_AnneeUniv;
    }

    /**
     * Sets parent relation FormationIdformation
     *
     * @param Application_Model_Formation $data
     * @return Application_Model_Semestre
     */
    public function setFormation(Application_Model_Formation $data)
    {
        $this->_Formation = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idformation'];
        }

        $this->setFormationIdformation($primary_key);

        return $this;
    }

    /**
     * Gets parent FormationIdformation
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Formation
     */
    public function getFormation($load = true)
    {
        if ($this->_Formation === null && $load) {
            $this->getMapper()->loadRelated('FkSemestreFormation', $this);
        }

        return $this->_Formation;
    }

    /**
     * Sets parent relation SemestreListIdsemestre
     *
     * @param Application_Model_SemestreList $data
     * @return Application_Model_Semestre
     */
    public function setSemestreList(Application_Model_SemestreList $data)
    {
        $this->_SemestreList = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idsemestre'];
        }

        $this->setSemestreListIdsemestre($primary_key);

        return $this;
    }

    /**
     * Gets parent SemestreListIdsemestre
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_SemestreList
     */
    public function getSemestreList($load = true)
    {
        if ($this->_SemestreList === null && $load) {
            $this->getMapper()->loadRelated('FkSemestreSemestreList1', $this);
        }

        return $this->_SemestreList;
    }

    /**
     * Sets dependent relations fk_courselot_semestre1
     *
     * @param array $data An array of Application_Model_Course
     * @return Application_Model_Semestre
     */
    public function setCourse(array $data)
    {
        $this->_Course = array();

        foreach ($data as $object) {
            $this->addCourse($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_courselot_semestre1
     *
     * @param Application_Model_Course $data
     * @return Application_Model_Semestre
     */
    public function addCourse(Application_Model_Course $data)
    {
        $this->_Course[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_courselot_semestre1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_Course
     */
    public function getCourse($load = true)
    {
        if ($this->_Course === null && $load) {
            $this->getMapper()->loadRelated('FkCourselotSemestre1', $this);
        }

        return $this->_Course;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_Semestre
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_Semestre());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_Semestre::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdsemestre() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('idsemestre = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdsemestre()));
    }
}
